<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>03计算属性实现</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo">
            <h2>{{school}}</h2>
            <input type="text" v-model='school'>
            <hr>
            姓: <input type="text" v-model='fristName'><br>
            名: <input type="text" v-model='lastName'><br>
            全名: <span>{{fullName}}</span>
            <hr>
            <button @click="changeFullName">点击修改成lisi</button>
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        new Vue({
            el:'#demo',
            data:{
                fristName:'zhang',
                lastName:'san',
                school:'尚硅谷'
            },
            methods:{
                changeFullName(){
                    this.fullName = 'Li-si';
                }
            },
            computed:{
                fullName:{
                    get(){
                        let {fristName,lastName} = this;
                        return  fristName[0].toUpperCase()+fristName.slice(1)+"-"+lastName
                    },
                    set(val){
                        const arr = val.split('-'); //拆分字符串
                        this.fristName = arr[0].toLowerCase();
                        this.lastName = arr[1];
                    }
                }
            }
        })
    </script>
</html>